<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <!-- 2021-3-2 16:06:16 qjh  锁定 可操作多条数据，经和大珺确认，故不展示操作记录了 -->
    <!-- <BreakSpace label='操作记录' />
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >

    </FilterTable>
    <div style="height:47px;"></div> -->

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">确 认</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">确 认</multiuse-button>
    </div>
  </div>
</template>
<script>
import { getList, postonLock } from '@/api/dealerSale/InventoryManagement/InventoryManagement';
export default {
  data() {
    return {
      formList: this.createdFrom(),
      issearch: false,
      fetchApi: () => {},
      fetchParams: {}
      // columns:this.createdTable()
    };
  },
  components: {},
  props: ['list'],
  methods: {
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '锁定信息'
        },

        {
          type: 'TEXT_AREA',
          label: '锁定备注',
          fieldName: 'reason',
          placeholder: '请输入',
          selfCols: 3,
          rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        }
      ];
    },
    // createdTable(){
    //   return [
    //     {
    //       title: '序号',
    //       dataIndex: 'index',
    //       width: 80,
    //       sorter: true,
    //       render: props => {
    //         return <span>{props.row.index + 1}</span>;
    //       }
    //     },
    //     {
    //       title: '操作人',
    //       dataIndex: 'czry',
    //       sorter: true,
    //       filter: true,
    //       filterType: 'input',
    //     },
    //     {
    //       title: '操作时间',
    //       dataIndex: 'czsj',
    //       sorter: true,
    //       filter: true,
    //       filterType: 'input',
    //     },
    //     {
    //       title: '操作类型',
    //       dataIndex: 'czlx',
    //       sorter: true,
    //       filter: true,
    //       filterType: 'input',
    //     },
    //     {
    //       title: '操作后状态',
    //       dataIndex: 'czhzt',
    //       sorter: true,
    //       filter: true,
    //       filterType: 'input',
    //     },
    //     {
    //       title: '操作备注',
    //       dataIndex: 'czbz',
    //       sorter: true,
    //       filter: true,
    //       filterType: 'input',
    //     },
    //   ]
    // },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else if (type == 2) {
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if(this.saveData.reason == '调拨锁定' || this.saveData.reason == '配车锁定' || this.saveData.reason == '采购退锁定' || this.saveData.reason == '实销退货入库锁定')
          return this.$notify({
              title: '失败',
              message: '备注不能是调拨锁定,配车锁定,采购退锁定和实销退货入库锁定',
              type: 'error'
            });
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          let arr = [];
          this.list.map(x => {
            arr.push(`${x.vehicleId}`);
          });
          json.type = 1;
          json.vehicleId = arr;
          json.status = 10041001;
          let res = await postonLock(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '锁定成功',
              type: 'success'
            });
            this.$emit('close', json);
          } else {
            this.saveData = null;
          }
        }
      }
    }
  }
};
</script>
